home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue26 / chessbrd / CHESSBRD.ZIP / CPP / CHTHREAD.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-08  |  6.1 KB  |  157 lines

  1. //---------------------------------------------------------------------------
  2. #ifndef ChThreadH
  3. #define ChThreadH
  4. //---------------------------------------------------------------------------
  5. #include <vcl\Classes.hpp>
  6. #include "CHTYPES.H"
  7.  
  8. //---------------------------------------------------------------------------
  9. //---------------------------------------------------------------------------
  10.  
  11. class ChessThread : public TThread
  12. {
  13. private:
  14.         //From Tom's Simple Chess Program:
  15.  
  16.         void __fastcall init(void);
  17.         BOOL __fastcall in_check(int s);
  18.         BOOL __fastcall attack(int sq,int s);
  19.         void __fastcall gen(void);
  20.         void __fastcall gen_caps(void);
  21.         void __fastcall gen_push(int from,int to,int bits);
  22.         void __fastcall gen_promote(int from,int to,int bits);
  23.         BOOL __fastcall makemove(move_bytes m);
  24.         void __fastcall takeback(void);
  25.         void __fastcall sort_pv(void);
  26.         void __fastcall sort(int from);
  27.         int  __fastcall quiesce(int alpha,int beta);
  28.         int  __fastcall search(int alpha,int beta,int depth);
  29.         void __fastcall think(void);
  30.         int  __fastcall eval(void);
  31.         void __fastcall init_eval(void);
  32.  
  33.          /* pcsq stands for piece/square table. It's indexed by the piece's color,
  34.         type, and square. The value of pcsq[LIGHT][KNIGHT][e5] might be 310
  35.         instead of just 300 because a knight on e5 is better than one on
  36.         one of the outer squares. */
  37.         int pcsq[2][6][64];
  38.  
  39.         int flip[64];
  40.         int pawn_pcsq[64];
  41.         int kingside_pawn_pcsq[64];
  42.         int queenside_pawn_pcsq[64];
  43.         int minor_pcsq[64];
  44.         int king_pcsq[64];
  45.         int endgame_king_pcsq[64];
  46.  
  47.         int color[64];  /* LIGHT, DARK, or EMPTY */
  48.         int piece[64];  /* PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING, or EMPTY */
  49.         int side;  /* the side to move */
  50.         int xside;  /* the side not to move */
  51.         int castle;  /* a bitfield with the castle permissions. if 1 is set,
  52.                         white can still castle kingside. 2 is white queenside.
  53.                         4 is black kingside. 8 is black queenside. */
  54.         int ep;  /* the en passant square. if white moves e2e4, the en passant
  55.                     square is set to e3, because that's where a pawn would move
  56.                     in an en passant capture */
  57.         int fifty;  /* the number of moves since a capture or pawn move, used
  58.                        to handle the fifty-move-draw rule */
  59.         int ply;  /* the half-move that we're on */
  60.  
  61.         /* this is the move stack. gen_dat is basically a list of move lists,
  62.            all stored back to back. gen_begin[x] is where the first move of the
  63.            ply x move list is (in gen_dat). gen_end is right after the last move. */
  64.         gen_rec gen_dat[MOVE_STACK];
  65.         int gen_begin[HIST_STACK],gen_end[HIST_STACK];
  66.  
  67.         int history[64][64];
  68.  
  69.         /* we need an array of hist_rec's so we can take back the
  70.            moves we make */
  71.         hist_rec hist_dat[HIST_STACK];
  72.  
  73.         int nodes;  /* the number of nodes we've searched */
  74.  
  75.         /* a triangular PV array */
  76.         move pv[HIST_STACK][HIST_STACK];
  77.         int pv_length[HIST_STACK];
  78.         BOOL follow_pv;
  79.  
  80.  
  81.         /* Now we have the mailbox array, so called because it looks like a
  82.            mailbox, at least according to Bob Hyatt. This is useful when we
  83.            need to figure out what pieces can go where. Let's say we have a
  84.            rook on square a4 (32) and we want to know if it can move one
  85.            square to the left. We subtract 1, and we get 31 (h5). The rook
  86.            obviously can't move to h5, but we don't know that without doing
  87.            a lot of annoying work. Sooooo, what we do is figure out a4's
  88.            mailbox number, which is 61. Then we subtract 1 from 61 (60) and
  89.            see what mailbox[60] is. In this case, it's -1, so it's out of
  90.            bounds and we can forget it. You can see how mailbox[] is used
  91.            in attack() in board.c. */
  92.  
  93.         int mailbox[120];
  94.         int mailbox64[64];
  95.  
  96.  
  97.         /* slide, offsets, and offset are basically the vectors that
  98.            pieces can move in. If slide for the piece is FALSE, it can
  99.            only move one square in any one direction. offsets is the
  100.            number of directions it can move in, and offset is an array
  101.            of the actual directions. */
  102.  
  103.         BOOL slide[6];
  104.         int offsets[6];
  105.         int offset[6][8];
  106.  
  107.  
  108.         /* This is the castle_mask array. We can use it to determine
  109.            the castling permissions after a move. What we do is
  110.            logical-AND the castle bits with the castle_mask bits for
  111.            both of the move's squares. Let's say castle is 1, meaning
  112.            that white can still castle kingside. Now we play a move
  113.            where the rook on h1 gets captured. We AND castle with
  114.            castle_mask[63], so we have 1&14, and castle becomes 0 and
  115.            white can't castle kingside anymore. */
  116.  
  117.         int castle_mask[64];
  118.  
  119.         /* values of the pieces */
  120.         int value[6];
  121.  
  122.         /* the piece letters, for print_board() */
  123.         char piece_char[6];
  124.  
  125.         /* the initial board state */
  126.  
  127.         int init_color[64];
  128.         int init_piece[64];
  129.  
  130.         //---------------------------------------------------------------------
  131.         bool StopThinkingNow;
  132.         bool *Thinking;
  133.         bool *WhiteToMove;
  134.         char *Position;
  135.         Square *EnPassant;
  136.         CastleSet *Castling;
  137.         int *SearchDepth;
  138.         MoveFunc Move;
  139.  
  140.         void __fastcall IntCopy (int *dest, const int *source, int count);
  141.         int  __fastcall ColorOfPiece (Square sq);
  142.         void __fastcall InitValues();
  143.         void __fastcall PerformMove(void);
  144.  
  145. protected:
  146.         void __fastcall Execute();
  147.  
  148. public:
  149.         __fastcall ChessThread(char *position, bool *whitetomove,
  150.             Square *enpassant, CastleSet *castling, bool *thinking,
  151.             int *searchdepth, MoveFunc move);
  152.         void __fastcall CancelThinking(void);
  153.  
  154. };
  155.  
  156. #endif
  157.